package com.bloom.spider.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bloom.common.annotation.Log;
import com.bloom.common.core.controller.BaseController;
import com.bloom.common.core.domain.AjaxResult;
import com.bloom.common.enums.BusinessType;
import com.bloom.spider.domain.SpiderConfig;
import com.bloom.spider.service.ISpiderConfigService;
import com.bloom.common.utils.poi.ExcelUtil;
import com.bloom.common.core.page.TableDataInfo;

/**
 * 爬虫配置Controller
 * 
 * @author bloom
 * @date 2021-04-28
 */
@RestController
@RequestMapping("/spider/spiderConfig")
public class SpiderConfigController extends BaseController
{
    @Autowired
    private ISpiderConfigService spiderConfigService;

    /**
     * 查询爬虫配置列表
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpiderConfig spiderConfig)
    {
        startPage();
        List<SpiderConfig> list = spiderConfigService.selectSpiderConfigList(spiderConfig);
        return getDataTable(list);
    }

    /**
     * 导出爬虫配置列表
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderConfig:export')")
    @Log(title = "爬虫配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpiderConfig spiderConfig)
    {
        List<SpiderConfig> list = spiderConfigService.selectSpiderConfigList(spiderConfig);
        ExcelUtil<SpiderConfig> util = new ExcelUtil<SpiderConfig>(SpiderConfig.class);
        return util.exportExcel(list, "爬虫配置数据");
    }

    /**
     * 获取爬虫配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(spiderConfigService.selectSpiderConfigById(id));
    }

    /**
     * 新增爬虫配置
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderConfig:add')")
    @Log(title = "爬虫配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpiderConfig spiderConfig)
    {
        return toAjax(spiderConfigService.insertSpiderConfig(spiderConfig));
    }

    /**
     * 修改爬虫配置
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderConfig:edit')")
    @Log(title = "爬虫配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpiderConfig spiderConfig)
    {
        return toAjax(spiderConfigService.updateSpiderConfig(spiderConfig));
    }

    /**
     * 删除爬虫配置
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderConfig:remove')")
    @Log(title = "爬虫配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(spiderConfigService.deleteSpiderConfigByIds(ids));
    }
}
